#include "display.h"
#include <stdio.h>
#include <string.h>
#include "my_task.h"

#ifdef DIS_ZHINENGJIAJU
void display_oled(SENSOR_CTL *sensor_ctl_his, SENSOR_CTL *sensor_ctl, SENSOR_CTL *sensor_tar, SYS_CTL *sys_ctl)
{
    char screen_buf[48] = {0};

    // 温度 湿度 光照
    // 阈值 温度 湿度 光照
    // 预览or报警状态 WiFi连接状态
    // 防止过度刷新
    if (sensor_ctl_his->val_Temp  != sensor_ctl->val_Temp ||
        sensor_ctl_his->val_Hum   != sensor_ctl->val_Hum ||
        sensor_ctl_his->val_Light != sensor_ctl->val_Light ||
        sensor_ctl_his->val_soil  != sensor_tar->val_soil ||
        sys_ctl->key_up_flag == 1)
        {
        sys_ctl->key_up_flag = 0;
        sensor_ctl_his->val_Temp  = sensor_ctl->val_Temp;
        sensor_ctl_his->val_Hum   = sensor_ctl->val_Hum;
        sensor_ctl_his->val_Light = sensor_ctl->val_Light;
        sensor_ctl_his->val_soil  = sensor_tar->val_soil;


        sprintf(screen_buf, "TE HU LIT SOIL    ");
        OLED_ShowString(0, 0, (uint8 *)screen_buf, 12, 0);

        memset(screen_buf, 0, sizeof(screen_buf));
        sprintf(screen_buf, "%02d %02d %03d %03d",
            sensor_ctl->val_Temp,
            sensor_ctl->val_Hum,
            sensor_ctl->val_Light,
            sensor_ctl->val_soil
        );
        OLED_ShowString(0, 14, (uint8 *)screen_buf, 12, 1);

        memset(screen_buf, 0, sizeof(screen_buf));
        sprintf(screen_buf, "-- -- --- %03d",
            // sensor_tar->val_Temp,
            // sensor_tar->val_Hum,
            // sensor_tar->val_Light,
            sensor_tar->val_soil
        );
        OLED_ShowString(0, 28, (uint8 *)screen_buf, 12, 1);

        memset(screen_buf, 0, sizeof(screen_buf));
        if (sys_ctl->wifi_status == 1) {
            sprintf(screen_buf, "wifi OK");
        } else {
            sprintf(screen_buf, "wifi ERROR");
        }
        OLED_ShowString(0, 42, (uint8 *)screen_buf, 12, 1);

        OLED_Refresh();
    }
}
#endif

#ifdef DIS_WENSHIDU
void display_oled(SENSOR_CTL *sensor_ctl_his, SENSOR_CTL *sensor_ctl, SENSOR_CTL *sensor_tar, SYS_CTL *sys_ctl)
{
    char screen_buf[48] = {0};

    // 温度 湿度 光照
    // 阈值 温度 湿度 光照
    // 预览or报警状态 WiFi连接状态
    // 防止过度刷新
    if (sensor_ctl_his->val_Temp  != sensor_ctl->val_Temp ||
        sensor_ctl_his->val_Hum   != sensor_ctl->val_Hum ||
        sensor_ctl_his->val_Light != sensor_ctl->val_Light ||
        sensor_ctl_his->val_Co2  != sensor_tar->val_Co2 ||
        sensor_ctl_his->val_smoke   != sensor_tar->val_smoke ||
        sys_ctl->key_up_flag == 1)
        {
        sys_ctl->key_up_flag = 0;
        sensor_ctl_his->val_Temp  = sensor_ctl->val_Temp;
        sensor_ctl_his->val_Hum   = sensor_ctl->val_Hum;
        sensor_ctl_his->val_Light = sensor_ctl->val_Light;
        sensor_ctl_his->val_Co2  = sensor_tar->val_Co2;
        sensor_ctl_his->val_smoke   = sensor_tar->val_smoke;
        sensor_ctl_his->val_people = sensor_ctl->val_people;


        sprintf(screen_buf, "temp hum pwm  key   ");
        OLED_ShowString(0, 0, (uint8 *)screen_buf, 12, 0);

        memset(screen_buf, 0, sizeof(screen_buf));
        sprintf(screen_buf, "%02d   %02d  %04d %d    ",
            sensor_ctl->val_Temp,
            sensor_ctl->val_Hum,
            sensor_ctl->val_pmw,
            sys_ctl->pid_hot_ctl
        );
        OLED_ShowString(0, 16, (uint8 *)screen_buf, 12, 1);

        memset(screen_buf, 0, sizeof(screen_buf));
        sprintf(screen_buf, "%02d   %02d",
            sensor_tar->val_Temp,
            sensor_tar->val_Hum
        );
        OLED_ShowString(0, 28, (uint8 *)screen_buf, 12, 1);

        memset(screen_buf, 0, sizeof(screen_buf));
        if (sys_ctl->wifi_status == 1) {
            sprintf(screen_buf, "BLE OK");
        } else {
            sprintf(screen_buf, "BLE ER");
        }
        OLED_ShowString(0, 42, (uint8 *)screen_buf, 12, 1);

        OLED_Refresh();
    }
}

#endif

